home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 8 / Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO / 047a / lex_yacc.arj / YACCLIB.PAS < prev    next >
Pascal/Delphi Source File  |  1989-11-22  |  3KB  |  79 lines

  1.  
  2. unit YaccLib;
  3.   (* V1.1 9-29-88 AG; to be loaded with parsers generated by Yacc
  4.      V2.0 2-25-89, 5-27-89 11-22-89 AG *)
  5.  
  6.   interface
  7.  
  8.   type YYSTYPE = integer;
  9.     (* default type used for semantic attributes; may be redefined
  10.        to fit the target application
  11.        note: if you use the %union definition in your Yacc specification
  12.        Yacc will put a redefinition of YYSTYPE in the generated header
  13.        file *)
  14.   const yymaxdepth = 1024;
  15.     (* size (number of stack positions) allocated for parser stack;
  16.        may be redefined (size actually needed for the stack is
  17.        yymaxdepth*(sizeOf(integer)+sizeOf(yystype)));
  18.        note that right recursive grammar rules in the Yacc specification
  19.        may increase stack space requirements *)
  20.   procedure yymsg(msg : string);
  21.     (* default message print routine for yyparse; prints msg on standard
  22.        output (currently, possible values for msg are `syntax error' and
  23.        `yyparse: stack overflow'); may be redefined
  24.        IMPORTANT: This routine replaces the UNIX Yacc `yyerror' routine
  25.        since the name `yyerror' is used for the error simulation routine
  26.        discussed below (which is implemented as the macro YYERROR in UNIX
  27.        Yacc). *)
  28.   procedure yydebugmsg(s : integer; act : string; x : integer);
  29.     (* debug message printing routine for yyparse; this routine is
  30.        only needed if a parser is compiled with `/Dyydebug'.
  31.        s denotes a parser state, act a parser action, and x can either
  32.        be <0 (undefined) or denotes a state, a grammar rule or an input
  33.        token, depending on act.
  34.        The default version prints a message of the form
  35.          [s] act x
  36.        on standard output (x is omitted if <0). yydebugmsg may be redefined,
  37.        e.g. to give more informative messages, write to a window, etc. *)
  38.  
  39.   (* the following variables and procedures are not declared in the Yacc
  40.      library, but directly in the Yacc output file:
  41.   var yychar : integer;
  42.     { current lookahead token for yyparse; may be useful in actions
  43.       (especially user-supplied error recovery routines); if value is
  44.       `any' (code 257), no lookahead symbol is present and next symbol
  45.       is obtained via yylex }
  46.   var yynerrs : integer;
  47.     { current error count; incremented by yyparse after each call to yymsg }
  48.   var yylval : yystype;
  49.     { value associated with current lookahead token (set by yylex)
  50.       note: declared in the header file }
  51.   procedure yyerror;
  52.     { simulates syntax error (syntactic error recovery is started, as if
  53.       the next input symbol was illegal) }
  54.   procedure yyerrok;
  55.     { force the parser to believe that an error has fully been recovered from }
  56.   procedure yyaccept;
  57.     { simulates accept action of the parser; yyparse accepts and returns 0 }
  58.   procedure yyabort;
  59.     { simulates abort action of the parser; yyparse aborts the parse and
  60.       returns 1 }
  61.   procedure yyclearin;
  62.     { deletes the current lookahead token }
  63.   *)
  64.  
  65.   implementation
  66.   procedure yymsg(msg : string);
  67.     begin
  68.       writeln(msg);
  69.     end(*yymsg*);
  70.   procedure yydebugmsg(s : integer; act : string; x : integer);
  71.     begin
  72.       write('[', s, '] ', act);
  73.       if x>=0 then
  74.         writeln(' ', x)
  75.       else
  76.         writeln
  77.     end(*yydebugmsg*);
  78.   end(*YaccLib*).
  79.